package cn.platform.service.impl;

import cn.platform.entity.HarmonyParentChildren;
import cn.platform.entity.Parent;
import cn.platform.entity.Teacher;
import cn.platform.mapper.HarmonyParentMapper;
import cn.platform.response.AResponse;
import cn.platform.service.HarmonyParentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.time.Year;
import java.util.List;

@Service
public class HarmonyParentServiceImpl implements HarmonyParentService {
    @Autowired
    private HarmonyParentMapper harmonyParentMapper;

    /**
     * 根据家长id查询家长信息
     *
     * @param id 家长id
     * @return AResponse res 家长的信息
     *
     * @author jyz
     */
    @Override
    public AResponse getRoleMessage(Integer id){
        AResponse res = new AResponse();
        res.setData(harmonyParentMapper.getRoleMessage(id));
        return res;
    }

    /**
     * 根据家长id查询其绑定的小孩
     *
     * @param id 用户id
     * @return AResponse res 用户的信息
     *
     * @author jyz
     */
    @Override
    public AResponse getParentChildren(Integer id){
        AResponse res = new AResponse();

        // 通过年份相减计算年级
        List<HarmonyParentChildren> childrens = harmonyParentMapper.getParentChildren(id);
        for (HarmonyParentChildren children: childrens){
            children.setGrade(String.valueOf(Year.now().getValue() - Integer.parseInt(children.getGrade()) + 1));
        }
        res.setData(childrens);
        return res;
    }
}
